<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>客户体检信息健康管理系统</title>
    <meta name="description" content="客户体检信息健康管理系统">
    <meta name="keywords" content="客户体检信息健康管理系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body>
<div id="app">
    <div class="content-header">
        <h1>健康咨讯管理<small>健康咨讯详情</small></h1>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--返回按钮-->
                <el-button type="primary" @click="back">返回</el-button>
                <!--标题-->
                <h4>{{information.title}}</h4>
                <div v-if="information.user">
                    发布人:{{information.user.username}}&nbsp;&nbsp;&nbsp;发布时间:{{formatDate(information.releaseTime)}}
                </div>
                <!--内容-->
                <p>
                    {{information.content}}
                </p>
            </div>
        </div>
    </div>

</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index_copy.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            information: {}
        },
        //钩子函数，VUE对象初始化完成后自动执行
        mounted() {
            this.findInformation()
        },
        methods: {
            back() {
                window.location.href = 'information.html';
            },
            //日期转字符串格式
            formatDate(dateStr) {
                if (dateStr != null) {
                    let newdateStr = dateStr.replace(/\d+(?=-[^-]+$)/, (a) => (parseInt(a, 10) - 1));  //字符串处理(月份)
                    let nums = newdateStr.match(/\d+/g);  //取数
                    let date = eval('new Date(' + nums + ')');  //转换
                    //重组
                    let datetime =
                        date.getFullYear() + "年" +  //年
                        ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "月" +  //月
                        (date.getDate() > 9 ? date.getDate() : ("0" + date.getDate())) + "日";  //日
                    return datetime;
                }

            },
            findInformation() {
                //获取localStorage的information
                let id = localStorage.getItem('informationId');
                axios.get('/information/findInformationById.do?id=' + id).then((result) => {
                    this.information = result.data.data
                    // console.log(this.information)
                }).catch((e) => {
                    console.log(e)
                });
            }
        }
    })
</script>
</html>